package com.beiding.fastmock.fram;

import jdk.nashorn.api.scripting.ScriptObjectMirror;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author 丁常磊
 * @date 2021/7/22 18:35
 */

public class ScriptFilter implements Filter {

    private ScriptObjectMirror obj;

    public ScriptFilter(ScriptObjectMirror obj) {
        this.obj = obj;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        if (obj.containsKey("doFilter")) {
            obj.callMember("doFilter", servletRequest, servletResponse, filterChain);
        }
    }
}
